package com.example.springbootdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.springbootdemo.entity.SysUser;
import com.example.springbootdemo.exception.BizException;
import com.example.springbootdemo.mapper.SysUserMapper;
import com.example.springbootdemo.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class SysUserServiceImpl implements ISysUserService {

    private SysUserMapper sysUserMapper;

    public SysUserServiceImpl(SysUserMapper sysUserMapper) {
        this.sysUserMapper = sysUserMapper;
    }

    @Override
    public SysUser getSysUserByName(String username) throws BizException {
        if(log.isDebugEnabled()) {
            log.debug("根据用户名 {} 查询用户信息", username);
        }
        SysUser sysUser = null;
        try {
            QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("username", username);

            sysUser = sysUserMapper.selectOne(queryWrapper);
        }catch (Exception ex) {
            log.error("根据用户名查询用户信息失败");
            throw new BizException("查询用户信息失败");
        }
        return sysUser;
    }
}
